define(['jquery','jqueryLin','swiper'], () => {
    class Header {
        constructor () {
          this.load()
          .then(()=>{
            this.lunbo()
            this.Inlogin()
            this.lunboLogin()
            this.denglu()
            this.outLogin()
            this.headerFixed()
            this.CartNumber()
          })
        }
        load() {
        return new Promise(resolve => {
            $("header").load('/html/modules/header.html',resolve)
        })
         
     }
     lunbo () {
        var mySwiper = new Swiper('.swiper-cont', {
            autoplay: true,
            direction: 'vertical', // 垂直切换选项
            loop: true, // 循环模式选项 
        })
     }
     Inlogin () {
        const getList = $.lin_getCookie('List')
             if(getList) {
               $('#is-login').removeClass('edit')
               $('.toubudenglu .login').addClass('edit')
               $('#is-login b').html(getList)
             }
     }
     lunboLogin () {
      var mySwiper = new Swiper('.swiper-container', {
        autoplay: true,
        loop: true, // 循环模式选项

        // 如果需要分页器
        pagination: {
            el: '.swiper-pagination',
        }
    })
     }
     denglu () {
      $('.btn-login').on('click',function () {
        const name = $('#nameInput').val(),
          pwd = $('#pwdInput').val()
       var storge = JSON.parse(localStorage.getItem('userInfo'))
       storge.forEach(item => {
           if(item.username == name && item.userpwd == pwd) {
               alert('登录成功')
               $.lin_setCookie('List', name , { path: '/'})
               location.href = '../index.html'
           }else{
               alert('登录失败,请输入正确的账号或者密码')
           }
       })

    })
    $('.btn-zhuce').on('click',function () {
        location.href = './zhuce.html'
    })
     }
     outLogin () {
        $('#logout').on('click',function () {
            var falg = confirm('你确定要退出吗？')
               if(falg){
                $.lin_setCookie('List', name , { expires:-1,path: '/'})
                $('.toubudenglu .login').removeClass('edit')
                $('#is-login').addClass('edit')
               }
        })
     }
     headerFixed () {
      window.onscroll = function () {
        
        let top = document.documentElement.scrollTop || document.body.scrollTop
        if (top > 500) {
            $('#headerBox').css({
                "position": "fixed",
                "top": "-150px",
                "left": "0px"
            })
        }
        if (top < 300) {
            $('#headerBox').css({
                "position": "relative",
                "top": "0px",
                "left": "0px",
                "z-index": "2"
            })
        }
    }
     }
     CartNumber () {
        var info = JSON.parse(localStorage.getItem("info"))
           if(info) {
             var arr = []
             info.forEach(item => {
                if(item.check){
                    arr.push(item.num)
                }
             })
            var res =  arr.reduce((num,shop)=> {
               return num += shop
             },0)
             $('#gouwuNum').html(res)
           }
      }
     }
     return new Header()
})